import ApiConfig from '../apiConfig'
class ConfigClass {
  constructor() {
    this.configMap = new Map()
    // Dynamically import all configuration files from the config directory except index.js
    const configFiles = import.meta.glob('./**/*.js', { eager: true })
    for (const [key, module] of Object.entries(configFiles)) {
      if (!key.includes('index.js')) {
        const configModule = module.default
        const name = key.replace('./', '').replace('.js', '').split('/').pop()
        this.configMap.set(configModule.name || name, configModule)
      }
    }
  }

  getTypes() {
    return this.configMap.keys()
  }

  getConfig(type) {
    return JSON.parse(JSON.stringify(this.configMap.get(type)))
  }
  setConfig(type, data) {
    this.configMap.set(type, data)
  }

  getApiConfig(key) {
    return ApiConfig.getApiConfig(key)
  }
  setApiConfig(key, config) {
    ApiConfig.setApiConfig(key, config)
  }
}

const config = new ConfigClass()

export default config
